import 'package:stage_app/model/user_info_entity.dart';

userInfoEntityFromJson(UserInfoEntity data, Map<String, dynamic> json) {
	if (json['avatar'] != null) {
		data.avatar = json['avatar']?.toString();
	}
	if (json['createTime'] != null) {
		data.createTime = json['createTime']?.toInt();
	}
	if (json['id'] != null) {
		data.id = json['id']?.toInt();
	}
	if (json['nickname'] != null) {
		data.nickname = json['nickname']?.toString();
	}
	if (json['phone'] != null) {
		data.phone = json['phone']?.toString();
	}
	if (json['status'] != null) {
		data.status = json['status']?.toInt();
	}
	if (json['updateTime'] != null) {
		data.updateTime = json['updateTime']?.toInt();
	}
	if (json['username'] != null) {
		data.username = json['username']?.toString();
	}
	if (json['roles'] != null) {
		data.roles = new List<UserRole>();
		(json['roles'] as List).forEach((v) {
			data.roles.add(new UserRole().fromJson(v));
		});
	}
	return data;
}

Map<String, dynamic> userInfoEntityToJson(UserInfoEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['avatar'] = entity.avatar;
	data['createTime'] = entity.createTime;
	data['id'] = entity.id;
	data['nickname'] = entity.nickname;
	data['phone'] = entity.phone;
	data['status'] = entity.status;
	data['updateTime'] = entity.updateTime;
	data['username'] = entity.username;
	if (entity.roles != null) {
		data['roles'] =  entity.roles.map((v) => v.toJson()).toList();
	}
	return data;
}

userRoleFromJson(UserRole data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id']?.toInt();
	}
	if (json['name'] != null) {
		data.name = json['name']?.toString();
	}
	return data;
}

Map<String, dynamic> userRoleToJson(UserRole entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['name'] = entity.name;
	return data;
}